//------auth: tc.tang 2007/05/15
//------control Standard BUTTON
/**
*IMG BUTTON FORMAT
*<span class="mainClass"><div class="but-left"></div><span class="text">text</span><div class="but-right"></div></span>
*this Utility class did not support imgButton yet.
*/

var button = {}//spc

 button.control = function(){};//class
 
 button.control = function(){
  //init the button
  this.id = arguments[0];
  this.buttonInstanceName = arguments[1];
  this.mainSpan = document.getElementById(this.id);
  var childDivs = this.mainSpan.getElementsByTagName("DIV");
  var childSpans= this.mainSpan.getElementsByTagName("SPAN");
  var childLinks= this.mainSpan.getElementsByTagName("A");
  this.leftButton = childDivs[0];
  this.rightButton= childDivs[1];
  this.textSpan = childSpans[0];
  if(childLinks&&childLinks.length>0){
    //enabled
    this.link = childLinks[0];
  }
  this.mainClass = this.mainSpan.className;
 }
 
 button.control.prototype.id = null;
 button.control.prototype.mainSpan = null;
 button.control.prototype.leftButton = null;
 button.control.prototype.rightButton = null;
 button.control.prototype.textSpan = null;
 button.control.prototype.link = null;
 button.control.prototype.linkHref = null;
 button.control.prototype.linkClick = "return(false)";
 button.control.prototype.status=true;//true=enabled false=disabled
 
 button.control.prototype.mainClass = "but-standard";//enabled,disabled
 button.control.prototype.mainDiabledClass ="but-standard-disabled";
 
 button.control.prototype.buttonInstanceName=null;
 
 //static ---
 button.control.instanceMap = new Array();
 
 /**
 *set the main-disabled class
 */
 button.control.prototype.setDisabledMainClass = function(className){
   this.mainDiabledClass = className;
 }
 /**
 *set the main-enabled class
 */
 button.control.prototype.setEnabledMainClass = function(className){
  this.mainClass= className;
 }
 /**
 *set button enabled/disabled
 */
 button.control.prototype.setDisabled = function(type){
   
   if(type&&this.status){//if button's status is disabled,do not set it to disabled again.
     //set disabled
     this.setButtonDisabled();
     this.status=false;
   }else if(!type&&!this.status){
     //set Enabled
     this.setButtonEnabled();
     this.status=true;
   }
 }
 
 button.control.prototype.setButtonDisabled = function(){
   this.mainSpan.className = this.mainDiabledClass;

   if(this.link){ 
     this.linkHref = this.link.href;
     this.linkClick = this.link.onclick;
     this.link.removeAttribute("href");//move the href attribute
     this.link.onclick="return (false)";
    } 
 }
 
 button.control.prototype.setButtonEnabled = function(){
   this.mainSpan.className = this.mainClass;
   if(this.link){
     this.link.setAttribute("href",this.linkHref,1);
     this.link.onclick = this.linkClick;
     //alert(this.link.onclick);
   }
 }
 
 //--static method
 /**
 *static metod set the enabled/disabled
 */
 button.control.setButtonDisabledType = function(buttonId,type,disabledCss){
   var buttonInstance = null;
   for(i=0;i<button.control.instanceMap.length;i++){
     var tempInstance = button.control.instanceMap[i];
     if(tempInstance.id==buttonId){
       buttonInstance = tempInstance;
       break;
     }
   }
   
   if(!buttonInstance){
     //new a instance
     buttonInstance = new button.control(buttonId,"buttonInstance");
     button.control.instanceMap.push(buttonInstance);
   }
   if(disabledCss!=null){
     buttonInstance.setDisabledMainClass(disabledCss);
     }
     buttonInstance.setDisabled(type);
 }
 